<template>
  <div class="m-login-container">
    <el-row class="m-main-header-search">
      <el-form hide-required-asterisk es="rules" :inline="true" ref="refForm">
        <el-form-item label="时间">
          <el-date-picker
            v-model="time"
            type="daterange"
            size="small"
            value-format="yyyy-MM-dd"
            format="yyyy-MM-dd"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          />
        </el-form-item>
        <el-form-item>
          <el-button @click="handleSearch()" type="primary" size="small">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <div class="m-main-content-body">
        <p class="contant-body-title">Roi</p>
      <el-table
        v-loading="loading"
        :data="list"
        tooltip-effect="dark"
        style="width: 100%"
        :inline="false"
        stripe
        :header-cell-style="{
          'background-color': '#E5EEFF',
        }"
      >
        <el-table-column prop="country" label="地区"> </el-table-column>
        <el-table-column prop="spent" label="消耗金额"></el-table-column>
        <el-table-column prop="roi" label="roi"></el-table-column>
        <el-table-column prop="date" label="日期"></el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          @size-change="(val) => handlePageMetaChange(val, 'size')"
          @current-change="(val) => handlePageMetaChange(val, 'page')"
          :current-page="pageMeta.page"
          :page-sizes="[10, 20, 30, 50]"
          :page-size="pageMeta.limit"
          layout="sizes, prev, next, jumper"
          :total="pageMeta.total"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  components: {},
  data() {
    return {
      list: [],
      loading: false,
      dislogSetVisible: false,
      refFormData: {},
      pageMeta: {
        page: 1,
        limit: 10,
        total: 1e10,
      },
      time: [
        this.$moment(new Date()).format("YYYY-MM-DD"),
        this.$moment(new Date()).format("YYYY-MM-DD"),
      ],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /*
     * @Desc: 获取列表
     * @params: {String}
     * @return: {Object}
     */
    async getList() {
      this.loading = true;
      const [start_time, end_time] = this.time;
      const { data } = await this.$api.roi.getRoiList({
        ...this.pageMeta,
        page: this.pageMeta.page - 1,
        ...this.refFormData,
        start_time: start_time + " 00:00:00",
        end_time: end_time + " 23:59:59",
      });
      const { code, data: list } = data;
      if (code === 200) {
        this.list = list;
      }
      this.loading = false;
    },

    /*
     * @Desc:
     * @params: {String}
     * @return: {Object}
     */
    async handleSearch() {
      this.pageMeta.page = 1;
      this.getList();
    },

    /**
     * @Desc 分页
     * @params {String} val page/limit
     * @params {String} type  page/size
     * @return {Object}
     * */
    handlePageMetaChange(val, type = "size") {
      this.pageMeta[type === "size" ? "limit" : "page"] = val;
      this.getList();
    },
  },
};
</script>

<style lang="less" scoped></style>
